﻿using Md.Api.Entity.DapperModels.MdDB;
using Md.Api.Model.Manage.MdWebNavigation.Request;
using Md.Dapper.Repositories.Md;

namespace Md.Api.Service.Manage.MdWebNavigation;
/// <summary>
/// 添加网站导航服务
/// </summary>
public class InsertMdWebNavigationService : ApiBase<RequestInsertMdWebNavigationModel>
{
    /// <summary>
    /// 网站导航仓储
    /// </summary>
    public MdWebNavigationRep mdWebNavigationRep { get; set; }
    /// <summary>
    /// 执行
    /// </summary>
    protected override void ExecuteMethod()
    {
        var model = new MdWebNavigationModel();

        model.Name = Parameter.Name;
        model.PagePath = Parameter.PagePath;
        model.Link = Parameter.Link;
        model.IsExternalLink = Parameter.IsExternalLink;
        model.ParentId = Parameter.ParentId;
        model.Remark = Parameter.Remark;
        model.CreateBy = userKey?.ToString();
        model.CreateTime = DateTime.Now;

        var res = mdWebNavigationRep.Insert(model);

        if (Convert.ToInt64(res) > 0)
        {
            Result.Data = mdWebNavigationRep.GetMdWebNavigationById(Convert.ToInt64(res));
        }
        else
        {
            Result.Data = res;
        }
    }
}

